package com.hsgene.security.controller;

import com.hsgene.common.util.result.ApiResult;
import com.hsgene.security.service.RSASecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 安全服务Controller
 *
 * @author wangbing
 * @version 1.0, 2018/7/11
 */
@RestController
@RequestMapping("/security")
public class SecurityController {

    @Autowired
    private RSASecurityService rsaSecurityService;

    /**
     * 解密指定加密数据
     *
     * @param encryptData 加密数据
     * @return 解密后的明文
     */
    @GetMapping("rsa/decrypt")
    public ApiResult<String> rsaDecrypt(
            @RequestParam("encryptData") String encryptData) {
        return ApiResult.succ(rsaSecurityService.decryptData(encryptData));
    }

    /**
     * 加密指定原始数据
     *
     * @param originData 原始数据
     * @return 加密后密文
     */
    @GetMapping("rsa/encrypt")
    public ApiResult<String> rsaEncrypt(
            @RequestParam("origin") String originData) {
        return ApiResult.succ(rsaSecurityService.encryptData(originData));
    }
}
